layui.use(["table", 'form', "util", "layer"], function () {
    var table = layui.table;
    var util = layui.util;
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;

    //触发事件(添加字典大类)
    $("#btnAdd").click(function () {
        layer.open({
            type: 1
            , resize: false
            , shadeClose: true
            , area: '350px'
            , title: '添加部门'
            , content: ['<ul class="layui-form layui-form-pane" style="margin: 15px;">'
                , '<li class="layui-form-item">'
                , '<label class="layui-form-label">部门职位</label>'
                , '<div class="layui-input-block">'
                , '<input class="layui-input" lay-verify="required" id="type">'
                , '</div>'
                , '</li>'
                , '<li class="layui-form-item" style="text-align:center;">'
                , '<button type="submit" lay-submit lay-filter="*" class="layui-btn">提交</button>'
                , '</li>'
                , '</ul>'].join('')
            , success: function (layero, index) {
                layero.find('.layui-layer-content').css('overflow', 'visible');

                form.render().on('submit(*)', function (data) {
                    //保存字典大类。
                    var dictName = $("#type").val();
                    if (dictName == '') {
                        layer.msg('请输入部门名称');
                        return;
                    }

                    console.log(dictName + "==============");
                    $.ajaxSettings.async = false;
                    $.post("/manageA/jjl_insertdp", "departmentName=" + dictName, function (data1) {
                        console.log(data1)
                        if (data1) {
                            layer.msg("添加成功",{
                                time:3000
                            });
                            window.location.reload();
                        } else {
                            layer.msg("添加失败",{
                                time:3000
                            });
                        }
                        layer.close(index);
                    });
                    $.ajaxSettings.async = true;

                });
            }
        });
    });

    table.on('tool(dictBigClassTable)', function (obj) {
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('真的要删除部门吗', function (index) {
                var param = {
                    id: data.id
                };
                $.ajax({
                    url: "/manageA/jjl_deldp",
                    type: "post",
                    data: param,
                    success: function (res) {
                        res = eval("(" + res + ")");
                        layer.msg(res.msg); //保存结果
                        if (res.resultCode == 0) { //save OK .
                            obj.del();
                        }
                        window.location.reload();
                    }
                });
            });
        } else if (obj.event === 'edit') {
            /**
             * 维护子字典（新弹出页面）
             */
            layer.open({
                type: 2,
                area: ['800px', '600px'],
                content: '/manageA/jjl_listjob?id=' + data.id + "&name=" +data.name
            });
        }
    });
});


